<template>
  <div class="container" id="cvs">
    <div class="left-board">
      <el-scrollbar class="left-scrollbar">
        <div class="components-list">
          <el-form
            class="cv_form"
            label-position="top"
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true">
            <div
              style="width: 100%;display: flex;justify-content: center;flex-direction: column;">
            <el-form-item
              label="Name"
              prop="name">
              <el-input
                v-model="queryParams.name"
                placeholder=""
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item
              label="Email"
              prop="email1">
              <el-input
                v-model="queryParams.email1"
                placeholder=""
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="Phone" prop="phone1">
              <el-input
                v-model="queryParams.phone1"
                placeholder=""
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label-width="80px" label="University" prop="schoolName">
              <el-input
                v-model="queryParams.schoolName"
                placeholder=""
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label-width="80px" label="Education" prop="education">
              <el-input
                v-model="queryParams.education"
                placeholder=""
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label-width="130px" label="Company Name" prop="companyName">
              <el-input
                v-model="queryParams.companyName"
                placeholder=""
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label-width="130px" label="Position Title" prop="position">
              <el-input
                v-model="queryParams.position"
                placeholder=""
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label-width="130px" label="Jobs Description" prop="jobDuties">
              <el-input
                v-model="queryParams.jobDesciption"
                placeholder=""
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>

            <el-form-item style="display: flex;justify-content: center;width: 100%;">
              <el-button
                type="primary"
                icon="el-icon-search"
                size="max"
                style="width: 200px;"
                @click="handleQuery">Search</el-button>
              <!--<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
            </el-form-item>
            </div>
          </el-form>
          <el-table
            :row-style="isRed"
            :show-header="false"
            v-loading="loading"
            :data="candidateList"
          >
            <el-table-column
              label="Email"
              align="center">
              <template slot-scope="scope">
                <div @click="handleEdit(scope.row)" style="
                display: flex;
                justify-content: center;
                align-items: center;
                cursor: pointer;
                height: 40px;">
                  <span>{{scope.row.email1}}</span>
                </div>
              </template>
            </el-table-column>
          </el-table>
          <pagination
            small
            layout="prev, pager, next"
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getCVList"
          />
        </div>
      </el-scrollbar>
    </div>

    <div class="right-board">
      <el-scrollbar class="left-scrollbar" ref="myScrollbar">
      <div class="components-list">
        <el-form
          ref="form"
          :model="form"
          :rules="rules"
          label-position="left"
          style="padding-left: 10px;padding-right: 10px;">
          <el-row>
            <el-col :span="24">
              <div>
                <span
                  style="color: #000;font-weight: bold;">Basic information</span>
              </div>
            </el-col>
          </el-row>
          <el-row style="margin-top: 20px;">
            <el-col :span="12">
              <el-form-item label-width="60px" label="Name" prop="name">
                <editor class="formName"  v-model="form.name" :min-height="1" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="Gender" prop="gender" style="margin-left: 10px;">
                <el-select v-model="form.gender" placeholder="">
                  <el-option
                    v-for="dict in dict.type.sys_user_sex"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <!--<el-col :span="12">-->
              <!--<el-form-item label-width="60px" label="District" prop="district">-->
                <!--<editor class="formName"  v-model="form.district" :min-height="1" />-->
              <!--</el-form-item>-->
            <!--</el-col>-->

            <el-col :span="12">
              <el-form-item label-width="60px" label="Area" prop="area">
                <el-select
                  v-model="form.area"
                  @change="selectAreaChange">
                  <el-option
                    v-for="dict in dict.type.sys_mhk_district"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="isMainlang">
              <el-form-item label-width="60px" label="District" v-if="isCascaderShow">
                <el-cascader
                  ref="cascader"
                  :options="options"
                  :props="{ multiple: false }"
                  v-model="optionsCity"
                  collapse-tags
                  clearable
                  @change="searchBuilds"
                  placeholder=""
                ></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="isHK">
              <el-form-item label-width="80px" label="District" prop="district">
                <el-select
                  v-model="form.district"
                  clearable
                  filterable
                  @blur="selectBlur"
                  @clear="selectClear"
                  @change="selectChange">
                  <el-option
                    v-for="dict in dict.type.sys_hk_district"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label-width="60px" label="Birth" prop="birthyear">
                <el-date-picker
                  v-model="form.birthyear"
                  value-format="yyyy"
                  type="year"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label-width="60px" label="Email" prop="email1">
                <editor class="formName"  v-model="form.email1" :min-height="1" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label-width="60px" label="Phone" prop="phone1" style="margin-left: 10px;">
                <editor class="formName"  v-model="form.phone1" :min-height="1" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>

          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="Expected salary" prop="salary">
                <el-input v-model="form.salary" placeholder="" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="Job function" prop="jobFunction">
                <el-input v-model="form.jobFunction" placeholder="" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row style="margin-top: 20px;">
            <el-col :span="12">
              <el-upload
                :action="uploadUrl"
                :on-preview="handlePreview"
                :on-remove="handleRemove"
                :before-remove="beforeRemove"
                accept=".pdf,.doc,.docx"
                name="file"
                :headers="headers"
                multiple
                :limit="100"
                ref="upload"
                :on-exceed="handleExceed"
                :on-success="handleFileSuccess"
                :file-list="form.fileList">
                <div style="display: flex;align-items: center;">
                  <i class="el-icon-upload" style="font-size: 35px;"></i>
                  <span style="color: #99a9bf;font-size: 15px;margin-left: 2px;">Upload</span>
                </div>
                <!--<el-button size="small" type="primary">点击上传</el-button>-->
                <div slot="tip" class="el-upload__tip">format pdf/word</div>
              </el-upload>
            </el-col>
          </el-row>

          <div style="margin-top: 50px;">
            <span style="color: #000;font-weight: bold;">Work experience</span>
            <div style="margin-top: 20px;">
              <el-form v-for=" (item,index) in form.ccompanyList"
                       :key="index" :model="item" :ref="'formData'+index"
                       label-width="80px"
                       style="border-bottom: 2px dotted #cccccc;margin-top: 10px">
                <div style="display: inline-flex;flex-direction: row-reverse;width: 100%;">
                  <el-button
                    @click="removeJobs(index)"
                    type="danger"
                    icon="el-icon-delete"
                    circle size="mini"></el-button>
                </div>
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="Company" prop="com">
                      <!--<el-input v-model="item.com" placeholder="" />-->
                      <editor class="formName"  v-model="item.com" :min-height="1" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label-width="60px" label="Title" prop="title" style="margin-left: 10px;">
                      <!--<el-input v-model="item.title" placeholder="" style="width: 200px;" />-->
                      <editor class="formName"  v-model="item.title" :min-height="1" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="Start Date">
                      <el-date-picker
                        v-model="item.startTime"
                        value-format="yyyy-MM"
                        type="month"
                      ></el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="End Date">
                      <el-date-picker
                        v-model="item.endTime"
                        value-format="yyyy-MM"
                        type="month"
                      ></el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="24">
                    <el-form-item label-width="80px" label="description">
                      <editor v-model="item.description" :min-height="392"/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </div>
            <el-button type="primary" round style="font-size: 12px;padding: 8px 12px;margin-top: 10px;" @click="addJobs">+Add New</el-button>
          </div>
          <div style="margin-top: 50px;">
            <span style="color: #000;font-weight: bold;">Education</span>
            <div style="margin-top: 20px;">
              <el-form v-for=" (item,index) in form.schoolList"
                       :key="index" :model="item" :ref="'formData'+index"
                       label-width="80px"
                       style="border-bottom: 2px dotted #cccccc;margin-top: 10px">
                <div style="display: inline-flex;flex-direction: row-reverse;width: 100%;">
                  <el-button
                    @click="removeSchool(index)"
                    type="danger"
                    icon="el-icon-delete"
                    circle size="mini"></el-button>
                </div>
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="School" prop="name">
                      <!--<el-input v-model="item.name" placeholder="" />-->
                      <editor class="formName"  v-model="item.name" :min-height="1" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label-width="60px" label="Major" prop="major" style="margin-left: 10px;">
                      <el-input v-model="item.major" placeholder="" style="width: 200px;" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="Degree" prop="degree">
                      <el-input v-model="item.degree" placeholder="" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="Start Date">
                      <el-date-picker
                        v-model="item.startTime"
                        value-format="yyyy-MM"
                        type="month"
                      ></el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="End Date">
                      <el-date-picker
                        v-model="item.endTime"
                        value-format="yyyy-MM"
                        type="month"
                      ></el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="24">
                    <el-form-item label-width="80px" label="description">
                      <editor v-model="item.description" :min-height="392"/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </div>
            <el-button type="primary" round style="font-size: 12px;padding: 8px 12px;margin-top: 10px;" @click="addSchool">+Add New</el-button>
          </div>
          <el-row>
            <p style="color: #000;font-weight: bold;margin-top: 50px;">Other</p>
            <el-col :span="24" style="margin-top: 10px;">
              <el-form-item label-width="0" label="">
                <editor v-model="form.other" :min-height="392"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div style="display: flex;width: 100%;">
          <el-button type="primary" @click="submitForm" style="margin-left: 50px;">Confirm</el-button>
<!--          <el-button @click="cancel" style="margin-left: 10px;">取 消</el-button>-->
        </div>

        <div style="width: 100%;margin-top: 30px;">
<!--          <p style="color: #8c939d;">Download Word CV</p>-->
          <el-button class="button-hover" :key="1" :disabled='downloadCVBool == 1 ? false:true' type="primary" @click="downloadWord">Download CV</el-button>
        </div>
      </div>
      </el-scrollbar>
    </div>
  </div>
</template>

<script>
import { listSearchCandidate, getCandidate, delCandidate, getCandidateDownload, updateCandidate } from "@/api/system/candidate";
import { getToken } from "@/utils/auth";
import { area } from '@/utils/area';
import { CodeToText } from 'element-china-area-data';
import {name} from '@/plugins/download';

export default {
  dicts: ['sys_hk_district', 'sys_normal_disable', 'sys_mhk_district', 'sys_user_sex'],
  data() {
    return {
      downloadCVBool: 0,
      isCascaderShow: false,
      isMainlang: false,
      isHK: false,
      loading: false,
      searchName: null,
      jobsData: {
        id: null,
        cid: null,
        com: null,
        title: null,
        startTime: null,
        endTime: null,
        description: null
      },
      schoolDate: {
        id: null,
        name: null,
        major: null,
        degree: null,
        description: null,
        startTime: null,
        endTime: null
      },
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      candidateList: [],
      candidateList2: [],
      // 弹出层标题
      title: "",
      uploadUrl: "http://jobslink.megaslink.com/prod-api" + "/common/upload", // process.env.VUE_APP_BASE_API上传的图片服务器地址
      headers: {
        Authorization: "Bearer " + getToken()
      },
      selectedArrData: [], // 把选择到的当前行的id存到数组中
      queryParams2: {
        id: null
      },
      // 查询参数
      queryParams: {
        id: null,
        pageNum: 1,
        pageSize: 10,
        email1: null,
        email2: null,
        name: null,
        companyName: null,
        position: null,
        schoolName: null,
        phone1: null,
        phone2: null,
        gender: null,
        salary: null,
        education: null,
        jobDesciption: null,
        other: null,
        district: null,
        age: null,
        birthyear: null
      },
      PopUpSarCh: "",
      optionsCity:[],
      // 表单参数
      fileData: {name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'},
      // 表单参数
      form: {
        id: null,
        email1: null,
        email2: null,
        name: null,
        phone1: null,
        phone2: null,
        gender: null,
        salary: null,
        education: null,
        other: null,
        district: null,
        age: null,
        birthyear: null,
        filePath: null,
        fileList: [],
        ccompanyList: [
          {
            id: null,
            cid: null,
            com: null,
            title: null,
            startTime: null,
            endTime: null,
            description: null
          }
        ],
        schoolList: [
          {
            id: null,
            name: null,
            major: null,
            degree: null,
            description: null,
            startTime: null,
            endTime: null
          }
        ]
      },
      // 表单校验
      rules: {
        email1: [
          { required: true, message: "email is null", trigger: "blur" }
        ],
        name: [
          { required: true, message: "name is null", trigger: "blur" }
        ],
        phone1: [
          { required: true, message: "phone is null", trigger: "blur" }
        ],
      },
    };
  },
  created() {
    // this.getCVList();
    this.$nextTick(() => {
      this.$refs.myScrollbar.wrap.scrollTop= 0;
    })
  },
  methods: {
    downloadWord(){
      this.loading = true;
      getCandidateDownload(this.form.id).then(response => {
        console.log(response);
        if (response.code == 200) {
          let filename = response.data.filename;
          this.$download.name(filename, false);
        }
      }).finally(f => {
        this.loading = false;
      });
    },
    searchBuilds() {
      let province = []
      let city = []
      let area = []
      let province1 = []
      let city1 = []
      let area1 = []
      if (this.optionsCity) {
        this.optionsCity.forEach((v) => {
          province.push(CodeToText[v[0]]) //中文的
          city.push(CodeToText[v[1]])
          area.push(CodeToText[v[2]])

          province1.push(v[0]) //编码的
          city1.push(v[1])
          area1.push(v[2])
        })
        province = Array.from(new Set(province)).toString()
        city = Array.from(new Set(city)).toString()
        area = Array.from(new Set(area)).toString()

        province1 = Array.from(new Set(province1)).toString()
        city1 = Array.from(new Set(city1)).toString()
        area1 = Array.from(new Set(area1)).toString()
      }
      console.log(province, 'province')
      console.log(city, 'city')
      console.log(area, 'area')
      console.log(province1, 'province1')
      console.log(city1, 'city1')
      console.log(area1, 'area1')
    },
    selectAreaChange(val) {
      this.form.area = val;
      if (this.form.area == 'HK') {
        this.isHK = true;
        this.isMainlang = false;
      } else {
        this.isHK = false;
        this.isMainlang = true;
        this.isCascaderShow = true;
      }
      this.$forceUpdate();
    },
    changeColorComList() {
      if (this.PopUpSarCh) {
        let replaceReg = new RegExp(this.PopUpSarCh, "ig");
        let replaceString = `<span style="background-color: #DE6;">${this.PopUpSarCh}</span>`;
        if (this.form.ccompanyList != null && this.form.ccompanyList.length > 0) {
          for (let i = 0; i < this.form.ccompanyList.length; i++) {
            this.form.ccompanyList[i].com = this.form.ccompanyList[i].com.replace(replaceReg, replaceString);
          }
        }
        // result[index].name = item.name.replace(replaceReg, replaceString);
      }
    },
    changeColorTitleList() {
      if (this.PopUpSarCh) {
        let replaceReg = new RegExp(this.PopUpSarCh, "ig");
        let replaceString = `<span style="background-color: #DE6;">${this.PopUpSarCh}</span>`;
        if (this.form.ccompanyList != null && this.form.ccompanyList.length > 0) {
          for (let i = 0; i < this.form.ccompanyList.length; i++) {
            this.form.ccompanyList[i].title = this.form.ccompanyList[i].title.replace(replaceReg, replaceString);
          }
        }
        // result[index].name = item.name.replace(replaceReg, replaceString);
      }
    },
    changeColorSearchList() {
      if (this.PopUpSarCh) {
        let replaceReg = new RegExp(this.PopUpSarCh, "ig");
        let replaceString = `<span style="background-color: #DE6;">${this.PopUpSarCh}</span>`;
        if (this.form.schoolList != null && this.form.schoolList.length > 0) {
          for (let i = 0; i < this.form.schoolList.length; i++) {
            this.form.schoolList[i].name = this.form.schoolList[i].name.replace(replaceReg, replaceString);
          }
        }
        // result[index].name = item.name.replace(replaceReg, replaceString);
      }
    },
    changeColorSearchItem(eml) {
      if (this.PopUpSarCh) {
        let replaceReg = new RegExp(this.PopUpSarCh, "ig");
        let replaceString = `<span style="background-color: #DE6;">${this.PopUpSarCh}</span>`;
        return eml.replace(replaceReg, replaceString);
        // result[index].name = item.name.replace(replaceReg, replaceString);
      }
    },
    changeColorItem() {
      if (this.PopUpSarCh) {
        let replaceReg = new RegExp(this.PopUpSarCh, "ig");
        let replaceString = `<span style="background-color: #DE6;">${this.PopUpSarCh}</span>`;
        this.form.name = this.form.name.replace(replaceReg, replaceString);
        // result[index].name = item.name.replace(replaceReg, replaceString);
      }
    },
    changeColorEmail() {
      if (this.PopUpSarCh) {
        let replaceReg = new RegExp(this.PopUpSarCh, "ig");
        let replaceString = `<span style="background-color: #DE6;">${this.PopUpSarCh}</span>`;
        this.form.email1 = this.form.email1.replace(replaceReg, replaceString);
        // result[index].name = item.name.replace(replaceReg, replaceString);
      }
    },
    changeColorPhone() {
      if (this.PopUpSarCh) {
        let replaceReg = new RegExp(this.PopUpSarCh, "ig");
        let replaceString = `<span style="background-color: #DE6;">${this.PopUpSarCh}</span>`;
        this.form.phone1 = this.form.phone1.replace(replaceReg, replaceString);
        // result[index].name = item.name.replace(replaceReg, replaceString);
      }
    },
    // 搜索关键词高亮方法
    changeColor(result) {
      //result为接口返回的数据
      result.map((item, index) => {
        if (this.PopUpSarCh) {
          /**
           * 使用正则表达式进行全文匹配关键词
           * ig : 表示 全文查找 ,忽略大小写
           *  i : 忽略大小写
           *  g : 全文查找
           *
           * 使用字符串的replace方法进行替换
           * stringObject.replace('被替换的值',替换的值)
           title和name是你要高亮的字段
           */
          let replaceReg = new RegExp(this.PopUpSarCh, "ig");
          let replaceString = `<span style="background-color: #DE6;">${this.PopUpSarCh}</span>`;
          if (item != null) {
            if (item.description != null && item.description != '') {
              result[index].description = item.description.replace(replaceReg, replaceString);
            }
          }
          // result[index].name = item.name.replace(replaceReg, replaceString);
        }
      });
      // this.records = result;
    },
    //编辑事件
    handleEdit(row){
      this.queryParams2.id = row.id;
      this.getList();
      this.selectedArrData = [row];
    },
    isRed({ row }) {
      const checkIdList = this.selectedArrData.map((item) => item.id);
      if (checkIdList.includes(row.id)) {
        return {
          backgroundColor: "#DE6",
          // color: "red",
        };
      }
    },
    cvdetail(data) {
      this.queryParams2.id = data;
      this.getList();
    },
    getCVList() {
      this.loading = true;
      listSearchCandidate(this.queryParams).then(response => {
        this.candidateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 获取pdf总页数
    getTotal() {
      // 多页pdf的src中不能直接使用后端获取的pdf地址 否则会按页数请求多次数据
      // 需要使用下述方法的返回值作为url
      this.pdfUrl = pdf.createLoadingTask(this.form.filePath)
      // 获取页码
      this.pdfUrl.promise.then(pdf => this.pageTotal = pdf.numPages).catch(error => {})
    },
    removeSchool(index) {
      if (this.form.schoolList.length <= 1) {
        this.$modal.msgError("最少保留一个");
        return;
      }
      this.form.schoolList.splice(index2, 1);
    },
    removeJobs(index) {
      if (this.form.ccompanyList.length <= 1) {
        this.$modal.msgError("最少保留一个");
        return;
      }
      this.form.ccompanyList.splice(index2, 1);
    },
    addSchool() {
      this.form.schoolList.push(this.schoolDate);
    },
    addJobs() {
      this.form.ccompanyList.push(this.jobsData);
    },
    handleRemove(file, fileList) {
      console.log(file);
      console.log(fileList);
      if (file.status == "success") {
        this.form.fileList = this.form.fileList.filter(item => {
          return !(item.name == file.name && item.url == file.url);
        } );
      }
      console.log(this.form.fileList);
    },
    handlePreview(file) {
      console.log(file);
      // 截取上传文件的后缀名
      let fileType = file.name.substring(file.name.lastIndexOf(".") + 1);
      console.log(fileType);
      // 判断文件名的类型，允许多种就判断多个
      if (fileType.toLocaleLowerCase() == 'pdf' || fileType.toLocaleLowerCase() == 'doc' || fileType.toLocaleLowerCase() == 'docx') {
        // if (fileType.toLocaleLowerCase() == 'pdf') {
        //   this.getTotal();
        //   this.openFile = true;
        // }  else {
        //   window.open('http://www.megaslink.com:8012/onlinePreview?url='+encodeURIComponent(Base64.encode(this.form.filePath)));
        // }
        let Base64 = require('js-base64').Base64
        window.open('http://www.megaslink.com:8012/onlinePreview?url='+encodeURIComponent(Base64.encode(this.form.filePath)));
      } else {
        this.$message.warning("文件类型必须为pdf,doc,docx格式")
        // 返回false 就不会执行上传操作了
        return false
      }
    },
    handleExceed(files, fileList) {
      // this.$message.warning(`当前限制只能上传 1 个文件或者删除重新上传`);
    },
    handleFileSuccess(response, file, fileList) {
      console.log(response);
      console.log(file);
      console.log(fileList);
      if (response.code == 200) {
        console.log("================" + response.url);
        this.form.filePath = response.url;
        this.form.fileList.push( {
            name: file.name,
            url: response.url
          }
        )
        console.log(this.form.fileList);
      } else {
        this.$message.warning(`上传失败`);
        // this.form.fileList.splice(this.form.fileList.length - 1, 1);
      }
      // fileList[0].response.url;

    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${ file.name }？`);
    },
    getList() {
      // this.$modal.closeLoading();
      listSearchCandidate(this.queryParams2).then(response => {
        this.candidateList2 = response.rows;
        if (this.candidateList2 != null) {
          this.form = this.candidateList2[0];

          if (this.form.cnAddr == null || this.form.cnAddr == '' || this.form.cnAddr == undefined) {

          } else {
            let optionsCityT = this.form.cnAddr.split(",");
            for (let i = 0; i < optionsCityT.length; i++) {
              this.optionsCity.push(parseInt(optionsCityT[i]));
            }
            console.log(this.optionsCity);
            this.$nextTick(() => {
              this.isCascaderShow = true;
            })
            console.log(this.isCascaderShow);
          }

          if (this.form.area == 'HK'){
            this.isHK = true;
            this.isMainlang = false;
          } else {
            this.isHK = false;
            this.isMainlang = true;
          }
          if (this.form.ccompanyList == null || this.form.ccompanyList.length == 0) {
            this.form.ccompanyList.push(this.jobsData)
          }
          if (this.queryParams.schoolName != null && this.queryParams.schoolName != '') {
            this.PopUpSarCh = this.queryParams.schoolName;
            this.changeColorSearchList();
          }
          if (this.queryParams.companyName != null && this.queryParams.companyName != '') {
            this.PopUpSarCh = this.queryParams.companyName;
            this.changeColorComList();
          }
          if (this.queryParams.position != null && this.queryParams.position != '') {
            this.PopUpSarCh = this.queryParams.position;
            this.changeColorTitleList();
          }
          if(this.queryParams.name != null && this.queryParams.name != '') {
            this.PopUpSarCh = this.queryParams.name;
            // this.changeColorItem();
            this.form.name = this.changeColorSearchItem(this.form.name);
          }
          if(this.queryParams.email1 != null && this.queryParams.email1 != '') {
            this.PopUpSarCh = this.queryParams.email1;
            this.changeColorEmail();
          }
          if(this.queryParams.phone1 != null && this.queryParams.phone1 != '') {
            this.PopUpSarCh = this.queryParams.phone1;
            this.changeColorPhone();
          }
          if (this.queryParams.jobDesciption != null) {
            this.PopUpSarCh = this.queryParams.jobDesciption;
            this.changeColor(this.form.ccompanyList);//调用搜索词方法
          }
          if (this.form.schoolList == null || this.form.schoolList.length == 0) {
            this.form.schoolList.push(this.schoolDate)
          }
          if (this.queryParams.education != null) {
            this.PopUpSarCh = this.queryParams.education;
            this.changeColor(this.form.schoolList);//调用搜索词方法
          }
          this.form.fileList = [];
          if (this.form.filePath != null && this.form.filePath != '') {
            this.form.fileListPath = this.form.filePath.split(",");
            for (let i = 0; i < this.form.fileListPath.length; i++) {
              this.form.fileList.push({
                name: this.form.fileListPath[i].substring(this.form.filePath.lastIndexOf('/') + 1),
                url: this.form.fileListPath[i]
              });
            }
          }
          this.downloadCVBool = 1;
          this.$nextTick(() => {
            this.$refs.myScrollbar.wrap.scrollTop= 0;
          })
        }
      });
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.handleQuery();
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.userName + '"用户吗？').then(function() {
        return changeUserStatus(row.userId, row.status);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
    // 取消按钮
    cancel() {

    },
    /** 搜索按钮操作 */
    handleQuery() {
      if ((this.queryParams.name != null && this.queryParams.name != '') ||
        (this.queryParams.email1 != null && this.queryParams.email1 != '') ||
        (this.queryParams.phone1 != null && this.queryParams.phone1 != '') ||
        (this.queryParams.education != null && this.queryParams.education != '') ||
        (this.queryParams.companyName != null && this.queryParams.companyName != '') ||
        (this.queryParams.schoolName != null && this.queryParams.schoolName != '') ||
        (this.queryParams.position != null && this.queryParams.position != '') ||
        (this.queryParams.jobDesciption != null && this.queryParams.jobDesciption != '')) {
        this.queryParams.pageNum = 1;
        this.getCVList();
      } else {
        this.$message.warning("no search condition");
        return;
      }

    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.deptId = undefined;
      this.$refs.tree.setCurrentKey(null);
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleResetPwd":
          this.handleResetPwd(row);
          break;
        case "handleAuthRole":
          this.handleAuthRole(row);
          break;
        default:
          break;
      }
    },
    /** 重置密码按钮操作 */
    handleResetPwd(row) {
      this.$prompt('请输入"' + row.userName + '"的新密码', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        inputPattern: /^.{5,20}$/,
        inputErrorMessage: "用户密码长度必须介于 5 和 20 之间"
      }).then(({ value }) => {
        resetUserPwd(row.userId, value).then(response => {
          this.$modal.msgSuccess("修改成功，新密码是：" + value);
        });
      }).catch(() => {});
    },
    /** 分配角色操作 */
    handleAuthRole: function(row) {
      const userId = row.userId;
      this.$router.push("/system/user-auth/role/" + userId);
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.filePath = '';
          if (this.optionsCity.length > 0) {
            this.form.cnAddr = this.optionsCity.join(',');
          }
          if (this.form.fileList != null && this.form.fileList.length > 0) {
            for (let i = 0; i < this.form.fileList.length; i++) {
              if (i == (this.form.fileList.length - 1)) {
                this.form.filePath = this.form.filePath + this.form.fileList[i].url;
              } else {
                this.form.filePath = this.form.filePath + this.form.fileList[i].url + ",";
              }
            }
          }
          if (this.form.id != null) {
            updateCandidate(this.form).then(response => {
              this.$modal.msgSuccess("success");
            });
          } else {

          }
        } else {
          this.$modal.msgWarning("fail,please check");
        }
      });
    }
  }
};
</script>

<style rel="stylesheet/scss" lang='scss'>
  .cv_form .el-form-item__label {
    line-height: 0px;
  }
.editor-tabs{
  background: #121315;
  .el-tabs__header{
    margin: 0;
    border-bottom-color: #121315;
    .el-tabs__nav{
      border-color: #121315;
    }
  }
  .el-tabs__item{
    height: 32px;
    line-height: 32px;
    color: #888a8e;
    border-left: 1px solid #121315 !important;
    background: #363636;
    margin-right: 5px;
    user-select: none;
  }
  .el-tabs__item.is-active{
    background: #1e1e1e;
    border-bottom-color: #1e1e1e!important;
    color: #fff;
  }
  .el-icon-edit{
    color: #f1fa8c;
  }
  .el-icon-document{
    color: #a95812;
  }
}

// home
.right-scrollbar {
  .el-scrollbar__view {
    padding: 12px 18px 15px 15px;
  }
}
.left-scrollbar .el-scrollbar__wrap {
  box-sizing: border-box;
  overflow-x: hidden !important;
  margin-bottom: 0 !important;
}
.center-tabs{
  .el-tabs__header{
    margin-bottom: 0!important;
  }
  .el-tabs__item{
    width: 50%;
    text-align: center;
  }
  .el-tabs__nav{
    width: 100%;
  }
}
.reg-item{
  padding: 12px 6px;
  background: #f8f8f8;
  position: relative;
  border-radius: 4px;
  .close-btn{
    position: absolute;
    right: -6px;
    top: -6px;
    display: block;
    width: 16px;
    height: 16px;
    line-height: 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    color: #fff;
    text-align: center;
    z-index: 1;
    cursor: pointer;
    font-size: 12px;
    &:hover{
      background: rgba(210, 23, 23, 0.5)
    }
  }
  & + .reg-item{
    margin-top: 18px;
  }
}
.action-bar{
  & .el-button+.el-button {
    margin-left: 15px;
  }
  & i {
    font-size: 20px;
    vertical-align: middle;
    position: relative;
    top: -1px;
  }
}

.custom-tree-node{
  width: 100%;
  font-size: 14px;
  .node-operation{
    float: right;
  }
  i[class*="el-icon"] + i[class*="el-icon"]{
    margin-left: 6px;
  }
  .el-icon-plus{
    color: #409EFF;
  }
  .el-icon-delete{
    color: #157a0c;
  }
}

.left-scrollbar .el-scrollbar__view{
  overflow-x: hidden;
}

.el-rate{
  display: inline-block;
  vertical-align: text-top;
}
.el-upload__tip{
  line-height: 1.2;
}

$selectedColor: #f6f7ff;
$lighterBlue: #409EFF;

.container {
  position: relative;
  width: 100%;
  height: 100%;
}

.components-list {
  padding: 8px;
  box-sizing: border-box;
  height: 100%;
  .components-item {
    display: inline-block;
    width: 48%;
    margin: 1%;
    transition: transform 0ms !important;
  }
}
.components-draggable{
  padding-bottom: 20px;
}
.components-title{
  font-size: 14px;
  color: #222;
  margin: 6px 2px;
  .svg-icon{
    color: #666;
    font-size: 18px;
  }
}

.components-body {
  padding: 8px 10px;
  background: $selectedColor;
  font-size: 12px;
  cursor: move;
  border: 1px dashed $selectedColor;
  border-radius: 3px;
  .svg-icon{
    color: #777;
    font-size: 15px;
  }
  &:hover {
    border: 1px dashed #787be8;
    color: #787be8;
    .svg-icon {
      color: #787be8;
    }
  }
}
.right-board {
  width: 70%;
  position: absolute;
  left: 30%;
  top: 0;
  height: 100vh;
  overflow: hidden;
  border-left: 0.5px solid #cccccc;
}
.left-board {
  width: 30%;
  position: absolute;
  left: 0;
  top: 0;
  height: 100vh;
  overflow: hidden;
}
.left-scrollbar{
  height: calc(100vh - 90px);
  overflow: hidden;
}
.center-scrollbar {
  height: calc(100vh - 42px);
  overflow: hidden;
  border-left: 1px solid #f1e8e8;
  border-right: 1px solid #f1e8e8;
  box-sizing: border-box;
}
.center-board {
  height: 100vh;
  width: auto;
  margin: 0 350px 0 260px;
  box-sizing: border-box;
}
.empty-info{
  position: absolute;
  top: 46%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 18px;
  color: #ccb1ea;
  letter-spacing: 4px;
}
.action-bar{
  position: relative;
  height: 42px;
  text-align: right;
  padding: 0 15px;
  box-sizing: border-box;;
  border: 1px solid #f1e8e8;
  border-top: none;
  border-left: none;
  .delete-btn{
    color: #F56C6C;
  }
}
.logo-wrapper{
  position: relative;
  height: 42px;
  background: #fff;
  border-bottom: 1px solid #f1e8e8;
  box-sizing: border-box;
}
.logo{
  position: absolute;
  left: 12px;
  top: 6px;
  line-height: 30px;
  color: #00afff;
  font-weight: 600;
  font-size: 17px;
  white-space: nowrap;
  > img{
    width: 30px;
    height: 30px;
    vertical-align: top;
  }
  .github{
    display: inline-block;
    vertical-align: sub;
    margin-left: 15px;
    > img{
      height: 22px;
    }
  }
}

.center-board-row {
  padding: 12px 12px 15px 12px;
  box-sizing: border-box;
  & > .el-form {
    // 69 = 12+15+42
    height: calc(100vh - 69px);
  }
}
.drawing-board {
  height: 100%;
  position: relative;
  .components-body {
    padding: 0;
    margin: 0;
    font-size: 0;
  }
  .sortable-ghost {
    position: relative;
    display: block;
    overflow: hidden;
    &::before {
      content: " ";
      position: absolute;
      left: 0;
      right: 0;
      top: 0;
      height: 3px;
      background: rgb(89, 89, 223);
      z-index: 2;
    }
  }
  .components-item.sortable-ghost {
    width: 100%;
    height: 60px;
    background-color: $selectedColor;
  }
  .active-from-item {
    & > .el-form-item{
      background: $selectedColor;
      border-radius: 6px;
    }
    & > .drawing-item-copy, & > .drawing-item-delete{
      display: initial;
    }
    & > .component-name{
      color: $lighterBlue;
    }
  }
  .el-form-item{
    margin-bottom: 15px;
  }
}
.drawing-item{
  position: relative;
  cursor: move;
  &.unfocus-bordered:not(.activeFromItem) > div:first-child  {
    border: 1px dashed #ccc;
  }
  .el-form-item{
    padding: 12px 10px;
  }
}
.drawing-row-item{
  position: relative;
  cursor: move;
  box-sizing: border-box;
  border: 1px dashed #ccc;
  border-radius: 3px;
  padding: 0 2px;
  margin-bottom: 15px;
  .drawing-row-item {
    margin-bottom: 2px;
  }
  .el-col{
    margin-top: 22px;
  }
  .el-form-item{
    margin-bottom: 0;
  }
  .drag-wrapper{
    min-height: 80px;
  }
  &.active-from-item{
    border: 1px dashed $lighterBlue;
  }
  .component-name{
    position: absolute;
    top: 0;
    left: 0;
    font-size: 12px;
    color: #bbb;
    display: inline-block;
    padding: 0 6px;
  }
}
.drawing-item, .drawing-row-item{
  &:hover {
    & > .el-form-item{
      background: $selectedColor;
      border-radius: 6px;
    }
    & > .drawing-item-copy, & > .drawing-item-delete{
      display: initial;
    }
  }
  & > .drawing-item-copy, & > .drawing-item-delete{
    display: none;
    position: absolute;
    top: -10px;
    width: 22px;
    height: 22px;
    line-height: 22px;
    text-align: center;
    border-radius: 50%;
    font-size: 12px;
    border: 1px solid;
    cursor: pointer;
    z-index: 1;
  }
  & > .drawing-item-copy{
    right: 56px;
    border-color: $lighterBlue;
    color: $lighterBlue;
    background: #fff;
    &:hover{
      background: $lighterBlue;
      color: #fff;
    }
  }
  & > .drawing-item-delete{
    right: 24px;
    border-color: #F56C6C;
    color: #F56C6C;
    background: #fff;
    &:hover{
      background: #F56C6C;
      color: #fff;
    }
  }
}
//去掉表格内的线
#cvs table th,
table td {
  /*border-bottom: none !important;*/
}
  #cvs .el-table {
  .el-table__body {
    //-webkit-border-horizontal-spacing: 13px;  // 水平间距
    -webkit-border-vertical-spacing: 10px; // 垂直间距 设置的是行间距
  }
}
//去掉最下面的那一条线
  #cvs .el-table::before {
  height: 0px;
}
  #cvs .customer-table .el-table__fixed-right::before,
.el-table__fixed::before {
  width: 0;
}
  #cvs .el-table .el-table__cell {
  border-radius: 10px;
  border: 1px solid #cccccc;
  padding: 0px 0;
}
  #cvs .el-form-item {
  margin-bottom: 10px;
}
  #cvs .el-table tbody tr:hover>td {
  border-radius: 10px;
  border: 1px solid #cccccc;
  background-color:#DE6 !important
  //修改成自己想要的颜色即可
}
  #cvs el-input {
  width: 200px;
}
  .formName .ql-toolbar {
    display: none;
  }
  .formName .ql-editor {
    border: 1px #DCDFE6 solid;
  }
  .ql-editor.ql-blank::before{
    content: "";
  }
/* 悬浮效果样式 */
.button-hover {
  position: fixed;
  right: 20px;
  bottom: 10%;
  z-index: 99999;
  padding: 13px;
  width: fit-content;
  opacity: 1;
  cursor: move;
  user-select: none;
  text-align: center;
}


</style>
